package com.zky.controller;

import com.zky.domain.ResponseResult;
import com.zky.domain.dto.TagListDto;
import com.zky.domain.entity.Tag;
import com.zky.domain.vo.PageVo;
import com.zky.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/tag")
public class TagController {
    @Autowired
    private TagService tagService;

    /**
     * 查询标签列表
     * @param pageNum    页面num
     * @param pageSize   页面大小
     * @param tagListDto 标记列表dto
     * @return {@link ResponseResult}
     */
    @GetMapping("/list")
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, TagListDto tagListDto){
        return tagService.pageTagList(pageNum,pageSize,tagListDto);
    }

    /**
     * 添加标签
     * @param tag    标签对象
     * @return {@link ResponseResult}
     */
    @PostMapping()
    public ResponseResult addTag(@RequestBody Tag tag){
        return tagService.addTag(tag);
    }

    /**
     * 根据标签id删除标签
     * @param id id
     * @return {@link ResponseResult}
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteTag(@PathVariable("id") Long id){
        return tagService.deleteTag(id);
    }

    /**
     * 根据标签id查询标签信息
     * @param id id
     * @return {@link ResponseResult}
     */
    @GetMapping("/{id}")
    public ResponseResult getTagById(@PathVariable("id") Long id){
        return tagService.getTagById(id);
    }

    /**
     * 更新标签
     * @return {@link ResponseResult}
     */
    @PutMapping()
    public ResponseResult updateTag(@RequestBody Tag tag){
        return tagService.updateTag(tag);
    }

    @GetMapping("/listAllTag")
    public ResponseResult listAllTag(){
        return tagService.listAllTag();
    }
}